home *** CD-ROM | disk | FTP | other *** search
- /*-------------------------------------------------------------
- * PCM 録音 for WHISPER
- * Copyright (c) 1990 Nanno-NETWORK Allright Reserved
- * Programmed & Designed by Hirokazu Fujinaka
- **** Edition History ***
- *--- date --- --- auther --- --- contents ---
- *1990 Oct. 13 H.Fujinaka 作成開始:初期バ-ジョン
- *--------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <snd.h>
- #include <string.h>
-
- #define ERROR (-1)
- /*-----------------------------------------------------
- *ファイル外部でサウンド関連の初期化がされていれば
- * INITEDを定義すること。
- *----------------------------------------------------*/
- #define INITED
-
-
- #define PCMCH 71
- #define MAXCH 1
-
- #define LINE 0
- #define CD 1
- #define MIC 2
- #define MODEM 3
-
- #define SRC_LNR 4
- #define SRC_LNL 8
- #define SRC_CDR 16
- #define SRC_CDL 32
- #define SRC_MIC 64
- #define SRC_MOD 128
-
- #define VOL_LIN 0
- #define VOL_CD 1
- #define VOL_MIC 2
- #define VOL_MOD 3
- /*----------------------------------------------------
- * 再生時のためのファイルヘッダ-構造体
- *---------------------------------------------------*/
- struct header { char name[8];
- long id;
- long length;
- long loop_pos;
- long loop_len;
- short int freq,
- adjust;
- char original_tone;
- char flag;
- short int reserved;
- } head;
-
- static
- int id=0, /* sound ID */
- src=MIC, /* input device */
- vol=127, /* volume */
- freq=20*1000, /* sampling freq. */
- trig=0; /* sampling level */
-
-
- #ifdef INITED
- static char *snd_w;
- #endif
-
- static char *buff;
-
-
-
- static void write_head(FILE *fd, char *name)
- {
- strncpy(head.name, name, 8);
- srand((unsigned int) 16387);
- head.id=(id == 0 ?((long)rand()) : id );
- head.length= (long) sizeof(buff);
- head.loop_pos= (long) (sizeof(buff)-1);
- head.loop_len= (long) 0;
- head.freq= (short int)freq;
- head.adjust= (short int)0;
- head.original_tone=(char) 60;
- head.flag= (char) 0;
- head.reserved= (short int)0;
- fwrite(&head,sizeof(head),1,fd);
-
- }
-
- static int write_file(char *name)
- { FILE *fd;
-
- if ( ( fd=fopen(name,"wb") ) == NULL )
- return (ERROR);
-
- write_head(fd, name);
- fwrite(buff,sizeof(buff),1,fd);
- fclose(fd);
- return( 0 );
- }
-
-
- static void setup_pcm()
- {
- SND_pcm_mode_set(MAXCH);
- SND_elevol_init();
- SND_elevol_mute(0);
- SND_elevol_set(src,vol,vol);
- }
-
-
- /*-----------------------------------------------------------------
- *
- * SND_make(char *file);
- *
- *
- * ファイル名は、こちらから指定して戻り値としてエラ-の有無を
- *
- * 通知していただけたら幸いです。
- *
- * 知命的エラ-(malloc,fopenなど)で (-1)
- * 録音中断なら 1
- * 正常録音なら 0
- *
- * で、オ-トトリガなら最高?かな・・・(こいつは、あくまで希望)
- *
- ---------------------------------------------------------------------*/
- static int init()
- {
- if ( (buff=(char *)malloc(65536)) == NULL ) return (ERROR);
- #ifdef INITED
- if ( (snd_w=(char *)malloc(16384)) == NULL) return (ERROR);
- SND_init(snd_w);
- #endif
- return ( 0 );
- }
-
-
-
- static int rec(char *filename)
- { int ret;
-
- setup_pcm();
- SND_pcm_rec(freq,buff,sizeof(buff),trig);
- ret=write_file(filename);
- return( ret );
-
- }
-
- static void term()
- {
- #ifdef INITED
- SND_end();
- free(snd_w);
- #endif
- SND_elevol_mute(0xB3);
- free(buff);
- }
-
-
- int SND_make( char *filename )
- { int result;
-
- result=init();
- if( result == 0 )
- {
- result=rec( filename );
- term();
- }
- return( result );
- }